feat: Add Security and Validation Modifiers to TestArbitrage #155
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR introduces two critical security modifiers to the
TestArbitragecontract, enhancing access control and input validation for trade execution. These modifiers provide a robust defense layer against unauthorized access and invalid trade parameters.Changes
1. Access Control Modifier -
onlyAuthorizedAdded a new modifier that restricts trade execution to authorized traders or the contract owner.
Implementation:
msg.senderis in theauthorizedTradersmapping OR is the contract ownerSecurity Benefits:
2. Trade Parameter Validation Modifier -
validTradeParamsAdded a comprehensive validation modifier that checks all trade parameters before execution.
Validations Implemented:
Router Validation:
Token Validation:
Fee Validation:
Profit Threshold Validation:
MIN_PROFIT_BPS <= minProfitBps <= MAX_BPSSlippage Validation:
MAX_SLIPPAGE_BPSDeadline Validation:
Security Benefits:
3. Documentation
Both modifiers include comprehensive NatSpec documentation:
4. Code Formatting
Applied
forge fmtto ensure consistent code styling across the contract.Files Changed
src/onchain/TestArbitrage.sol- Added modifiers section with 36 new linesTesting Recommendations
When reviewing/merging this PR, consider adding tests for:
validTradeParams(boundary testing)Security Impact
Risk Level: Low (adds security, doesn't remove any)
These modifiers strengthen the contract's security posture by:
Breaking Changes
None. These modifiers are additions and don't modify existing functionality until applied to functions.
Next Steps
These modifiers should be applied to relevant trade execution functions in subsequent commits to enforce the validation and access control rules.